logo

NBIS Report

16-Nov-2019


NBIS ID: 1234
Report Version: 1.0
Request by: Name name ()
Principal Investigator: Name name ()
Organisation: Some University
NBIS Staff: Name name ()


1 RMarkdown

  • This is an RMarkdown document.
  • Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
  • Refer here for a guide.
  • .Rmd documents can be rendered as such:

2 Layout

Use <div>content</div> for block content and <span>content</span> for inline content.

For paragraphs, use <p>content</p>. And use classes text-left, text-center and text-right to align text left, center and right respectively.

<p class="text-right" style="background-color: aliceblue">This content is aligned right.</p>
<p class="text-center" style="background-color: aliceblue">This content is aligned center.</p>

This content is aligned right.

This content is aligned center.


Content can be organised into columns using pull-left-XX or pull-right-XX. Classes for 30, 40, 50, 60 and 70 have been implemented for left and right. Note that the total width must sum to 100.

<div class="pull-left-50" style="background-color: aliceblue">This content is pulled left.</div>
<div class="pull-right-50 text-center" style="background-color: aliceblue">This content is pulled right and text centered.</div>
This content is pulled left.
This content is pulled right and text centered.


<div class="pull-left-30" style="background-color: aliceblue">This content is pulled left.</div>
<div class="pull-right-70" style="background-color: aliceblue">This content is pulled right.</div>
This content is pulled left.
This content is pulled right.


This is an example of nested columns.

<div class="pull-left-30" style="background-color: aliceblue">This column is pulled left.</div>
<div class="pull-right-70" style="background-color: aliceblue">
This column is pulled right.
<div class="pull-left-50" style="background-color: #d0ece7">
Nested left.
</div>
<div class="pull-right-50" style="background-color: #f2d7d5">
Nested right.
</div>
</div>
This column is pulled left.
This column is pulled right.

Nested left.

Nested right.


3 Text formatting

Headings can be defined as shown below.

## Level 2 heading  
### Level 3 heading  
#### Level 4 heading  
##### Level 5 heading  
###### Level 6 heading 

3.1 Level 2 heading

3.1.1 Level 3 heading

3.1.1.1 Level 4 heading

3.1.1.1.1 Level 5 heading
3.1.1.1.1.1 Level 6 heading

Six custom classes are defined for text scaling. This can be defined inside a paragraph (<p>) or <span>.

<span class="largest">Largest text.</span>   
<span class="larger">Larger text.</span>  
<span class="large">Large text.</span>  
Normal text.  
<span class="small">Small text.</span>  
<span class="smaller">Smaller text.</span>  
<span class="smallest">Smallest text.</span>  

Largest text.
Larger text.
Large text.
Normal text.
Small text.
Smaller text.
Smallest text.

A horizontal line can be created using three or more * or -.

***


This is __Bold text__ This is Bold text
This is _Italic text_ This is Italic text
~~Strikethrough~~ text Strikethrough text
This is Subscript H~2~O displayed as H2O
This is Superscript 2^10^ displayed as 210
This is a [link](r-project.org) This is a link
An example of footnote reference 1

> This is a block quote. This
> paragraph has two lines.
>
> 1. This is a list inside a block quote.
> 2. Second item.

This is a block quote. This paragraph has two lines.

  1. This is a list inside a block quote.
  2. Second item.

4 Code formatting

Code can be defined inline where `this` looks like this. R code can be executed inline `r Sys.Date()` producing 2019-11-16. Code can also be defined inside code blocks.

```
This is code
```
This is code

R code is executed inside code blocks like this

```{r}
Sys.Date()
``` 

which shows the code and output.

## [1] "2019-11-16"

The code and results can be hidden by ```{r,echo=FALSE,results='hide'}`.

Here is another example of executed R code with input and output.

5 Lists

5.1 Bulleted List

Unordered lists are created using asterisks.

  • Bullet 1
  • Bullet 2
    • Sub-bullet 2.1
    • Sub-bullet 2.2
  • Bullet 3

Ordered lists are created using numbers.

  1. Point 1
  2. Point 2
  3. Point 3

6 Images

6.1 Using Markdown

Using regular markdown.

![](assets/cover.jpg)

The dimensions are based on image and/or fill up the entire available space. You can control the dimension as shown below.

![](assets/cover.jpg){width=30%}  

This image above is now 30% of it’s original width.

6.2 Using HTML

This image below is 30% size.
<img src="assets/cover.jpg" style="width:30%;"/>

This image below is 30% size, has shadow and corners rounded.
<img src="assets/cover.jpg" style="width:30%;" class="fancyimage"/>

6.3 Using R

R chunks in RMarkdown can be used to control image display size using the arguemnt out.width.

This image below is displayed at a size of 300 pixels.

```{r,out.width=300}
knitr::include_graphics('assets/cover.jpg')
``` 

This image below is displayed at a size of 75 pixels.

```{r,out.width=75}
knitr::include_graphics('assets/cover.jpg')
``` 

7 Math expressions

Some examples of rendering equations.

$e^{i\pi} + 1 = 0$

\(e^{i\pi} + 1 = 0\)

$$\frac{E \times X^2 \prod I}{2+7} = 432$$

\[\frac{E \times X^2 \prod I}{2+7} = 432\]

$$\sum_{i=1}^n X_i$$

\[\sum_{i=1}^n X_i\]

$$\int_0^{2\pi} \sin x~dx$$

\[\int_0^{2\pi} \sin x~dx\]

$\left( \sum_{i=1}^{n}{i} \right)^2 = \left( \frac{n(n-1)}{2}\right)^2 = \frac{n^2(n-1)^2}{4}$

\(\left( \sum_{i=1}^{n}{i} \right)^2 = \left( \frac{n(n-1)}{2}\right)^2 = \frac{n^2(n-1)^2}{4}\)

$\begin{eqnarray} X & \sim & \mathrm{N}(0,1)\\ Y & \sim & \chi^2_{n-p}\\ R & \equiv & X/Y \sim t_{n-p} \end{eqnarray}$

\(\begin{eqnarray} X & \sim & \mathrm{N}(0,1)\\ Y & \sim & \chi^2_{n-p}\\ R & \equiv & X/Y \sim t_{n-p} \end{eqnarray}\)

$\begin{eqnarray} P(|X-\mu| > k) & = & P(|X-\mu|^2 > k^2)\\ & \leq & \frac{\mathbb{E}\left[|X-\mu|^2\right]}{k^2}\\ & \leq & \frac{\mathrm{Var}[X]}{k^2} \end{eqnarray}$

\(\begin{eqnarray} P(|X-\mu| > k) & = & P(|X-\mu|^2 > k^2)\\ & \leq & \frac{\mathbb{E}\left[|X-\mu|^2\right]}{k^2}\\ & \leq & \frac{\mathrm{Var}[X]}{k^2} \end{eqnarray}\)

8 Tables

8.1 Paged

View of the data using paged tables. This is the default output for RMarkdown.

Tab. 1: Table using paged tibble.

8.2 kable

The most simple table using kable from R package knitr.

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa

8.3 kableExtra

More advanced table using kableExtra and formattable.

Tab. 2: Table using kableextra.

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
7.0 3.2 4.7 1.4 versicolor
6.4 3.2 4.5 1.5 versicolor
6.9 3.1 4.9 1.5 versicolor
6.5 3.0 5.8 2.2 virginica
7.6 3.0 6.6 2.1 virginica
4.9 2.5 4.5 1.7 virginica
7.3 2.9 6.3 1.8 virginica

8.4 DT

Interactive table using R package DT.

Tab. 3: Table using datatable.

9 Static plots

9.1 Base plot

  • Plots using base R are widely used and may be good enough for most situations.
  • But they lack a consistent coding framework.

Fig. 1: Static plot using base plot.

9.2 ggplot2

R package ggplot2 is one of the most versatile and complete plotting solutions.

Fig. 2: Static plot using ggplot2.

10 Interactive plots

10.1 highcharter

R package highcharter is a wrapper around javascript library highcharts.

Fig. 3: Interactive scatterplot using highcharter.

10.2 plotly

R package plotly provides R binding around javascript plotting library plotly.

Fig. 4: Interactive scatterplot using plotly.

10.3 ggplotly

plotly also has a function called ggplotly which converts a static ggplot2 object into an interactive plot.

Fig. 5: Interactive scatterplot using ggplotly.

10.4 ggiraph

ggiraph is also an R package that can be used to convert a static ggplot2 object into an interactive plot.

Fig. 6: Interactive scatterplot using ggiraph.

10.5 dygraphs

R package dygraphs provides R bindings for javascript library dygraphs for time series data.

Fig. 7: Interactive time series plot using dygraph.

10.6 Network graph

R package networkD3 allows the use of interactive network graphs from the D3.js javascript library.

Fig. 8: Interactive network plot.

10.7 leaflet

R package leaflet provides R bindings for javascript mapping library; leafletjs.

44.244167, 7.769444 Fig. 9: Interactive map using leaflet.

10.8 crosstalk

R package crosstalk allows crosstalk enabled plotting libraries to be linked. Through the shared ‘key’ variable, data points can be manipulated simultaneously on two independent plots.

Fig. 10: Linking independent plots using crosstalk.

11 General tips

  • Add custom css under YAML css: ["default", "my-theme.css"]
  • Export HTML to PDF using pkgdown and chrome pagedown::chrome_print("report.html",output="report.pdf")
  • Check out Rstudio’s RMarkdown tutorial
  • Input code from code chunks are displayed by default. Use echo=FALSE in code chunks to hide input code.
  • Data.frames are displayed as ‘paged’ interactive style. To display code-like data.frame, in YAML, set df_print: default.


Built on: 16-Nov-2019.


2019SciLifeLabNBIS


  1. That reference refers to this footnote.